﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用
namespace FiberRMS.DAL.AlarmManager
{
    /// <summary>
    /// 数据访问类ALARM_HISTORY。
    /// </summary>
    public class ALARM_HISTORY
    {
        public ALARM_HISTORY()
        { }
        #region  成员方法

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string ALARMNUMBER)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from ALARM_HISTORY");
            strSql.Append(" where ALARMNUMBER=:ALARMNUMBER ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,50)};
            parameters[0].Value = ALARMNUMBER;

            return OracleHelper.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(FiberRMS.Model.AlarmManager.ALARM_HISTORY model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into ALARM_HISTORY(");
            strSql.Append("ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,ALARMDESC,PRIMALCAUSE,ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,PERSISTTIME,ISSYNC,OBJECTCODE,OBJCLASS,ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME)");
            strSql.Append(" values (");
            strSql.Append(":ALARMNUMBER,:ENDTIME,:ISCLEARED,:CLEARPERSON,:ALARMEXPLAIN,:BELONGEQUIP,:BELONGTRANSYS,:BELONGSTATION,:RECORDDATE,:ALARMDESC,:PRIMALCAUSE,:ALARMOBJECT,:TRANTYPE,:VENDOR,:BELONGDOMAIN,:EQUIPMODEL,:PACKTYPE,:PREEQUIP,:PRESTATION,:DEDUSEFAULT,:PERSISTTIME,:ISSYNC,:OBJECTCODE,:OBJCLASS,:ALARMTYPE,:PROBABLECAUSE,:ALARMTEXT,:ALARMLEVEL,:STARTTIME)");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,20),
					new OracleParameter(":ENDTIME", OracleType.DateTime),
					new OracleParameter(":ISCLEARED", OracleType.VarChar,2),
					new OracleParameter(":CLEARPERSON", OracleType.VarChar,20),
					new OracleParameter(":ALARMEXPLAIN", OracleType.VarChar,255),
					new OracleParameter(":BELONGEQUIP", OracleType.VarChar,255),
					new OracleParameter(":BELONGTRANSYS", OracleType.VarChar,100),
					new OracleParameter(":BELONGSTATION", OracleType.VarChar,65),
					new OracleParameter(":RECORDDATE", OracleType.DateTime),
					new OracleParameter(":ALARMDESC", OracleType.VarChar,255),
					new OracleParameter(":PRIMALCAUSE", OracleType.VarChar,100),
					new OracleParameter(":ALARMOBJECT", OracleType.VarChar,64),
					new OracleParameter(":TRANTYPE", OracleType.VarChar,3),
					new OracleParameter(":VENDOR", OracleType.VarChar,20),
					new OracleParameter(":BELONGDOMAIN", OracleType.VarChar,20),
					new OracleParameter(":EQUIPMODEL", OracleType.VarChar,12),
					new OracleParameter(":PACKTYPE", OracleType.VarChar,20),
					new OracleParameter(":PREEQUIP", OracleType.VarChar,33),
					new OracleParameter(":PRESTATION", OracleType.VarChar,20),
					new OracleParameter(":DEDUSEFAULT", OracleType.VarChar,1),
					new OracleParameter(":PERSISTTIME", OracleType.VarChar,64),
					new OracleParameter(":ISSYNC", OracleType.VarChar,2),
					new OracleParameter(":OBJECTCODE", OracleType.VarChar,255),
					new OracleParameter(":OBJCLASS", OracleType.VarChar,40),
					new OracleParameter(":ALARMTYPE", OracleType.VarChar,50),
					new OracleParameter(":PROBABLECAUSE", OracleType.VarChar,40),
					new OracleParameter(":ALARMTEXT", OracleType.VarChar,255),
					new OracleParameter(":ALARMLEVEL", OracleType.VarChar,32),
					new OracleParameter(":STARTTIME", OracleType.DateTime)};
            parameters[0].Value = model.ALARMNUMBER;
            parameters[1].Value = model.ENDTIME;
            parameters[2].Value = model.ISCLEARED;
            parameters[3].Value = model.CLEARPERSON;
            parameters[4].Value = model.ALARMEXPLAIN;
            parameters[5].Value = model.BELONGEQUIP;
            parameters[6].Value = model.BELONGTRANSYS;
            parameters[7].Value = model.BELONGSTATION;
            parameters[8].Value = model.RECORDDATE;
            parameters[9].Value = model.ALARMDESC;
            parameters[10].Value = model.PRIMALCAUSE;
            parameters[11].Value = model.ALARMOBJECT;
            parameters[12].Value = model.TRANTYPE;
            parameters[13].Value = model.VENDOR;
            parameters[14].Value = model.BELONGDOMAIN;
            parameters[15].Value = model.EQUIPMODEL;
            parameters[16].Value = model.PACKTYPE;
            parameters[17].Value = model.PREEQUIP;
            parameters[18].Value = model.PRESTATION;
            parameters[19].Value = model.DEDUSEFAULT;
            parameters[20].Value = model.PERSISTTIME;
            parameters[21].Value = model.ISSYNC;
            parameters[22].Value = model.OBJECTCODE;
            parameters[23].Value = model.OBJCLASS;
            parameters[24].Value = model.ALARMTYPE;
            parameters[25].Value = model.PROBABLECAUSE;
            parameters[26].Value = model.ALARMTEXT;
            parameters[27].Value = model.ALARMLEVEL;
            parameters[28].Value = model.STARTTIME;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(FiberRMS.Model.AlarmManager.ALARM_HISTORY model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ALARM_HISTORY set ");
            strSql.Append("ENDTIME=:ENDTIME,");
            strSql.Append("ISCLEARED=:ISCLEARED,");
            strSql.Append("CLEARPERSON=:CLEARPERSON,");
            strSql.Append("ALARMEXPLAIN=:ALARMEXPLAIN,");
            strSql.Append("BELONGEQUIP=:BELONGEQUIP,");
            strSql.Append("BELONGTRANSYS=:BELONGTRANSYS,");
            strSql.Append("BELONGSTATION=:BELONGSTATION,");
            strSql.Append("RECORDDATE=:RECORDDATE,");
            strSql.Append("ALARMDESC=:ALARMDESC,");
            strSql.Append("PRIMALCAUSE=:PRIMALCAUSE,");
            strSql.Append("ALARMOBJECT=:ALARMOBJECT,");
            strSql.Append("TRANTYPE=:TRANTYPE,");
            strSql.Append("VENDOR=:VENDOR,");
            strSql.Append("BELONGDOMAIN=:BELONGDOMAIN,");
            strSql.Append("EQUIPMODEL=:EQUIPMODEL,");
            strSql.Append("PACKTYPE=:PACKTYPE,");
            strSql.Append("PREEQUIP=:PREEQUIP,");
            strSql.Append("PRESTATION=:PRESTATION,");
            strSql.Append("DEDUSEFAULT=:DEDUSEFAULT,");
            strSql.Append("PERSISTTIME=:PERSISTTIME,");
            strSql.Append("ISSYNC=:ISSYNC,");
            strSql.Append("OBJECTCODE=:OBJECTCODE,");
            strSql.Append("OBJCLASS=:OBJCLASS,");
            strSql.Append("ALARMTYPE=:ALARMTYPE,");
            strSql.Append("PROBABLECAUSE=:PROBABLECAUSE,");
            strSql.Append("ALARMTEXT=:ALARMTEXT,");
            strSql.Append("ALARMLEVEL=:ALARMLEVEL,");
            strSql.Append("STARTTIME=:STARTTIME");
            strSql.Append(" where ALARMNUMBER=:ALARMNUMBER ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,20),
					new OracleParameter(":ENDTIME", OracleType.DateTime),
					new OracleParameter(":ISCLEARED", OracleType.VarChar,2),
					new OracleParameter(":CLEARPERSON", OracleType.VarChar,20),
					new OracleParameter(":ALARMEXPLAIN", OracleType.VarChar,255),
					new OracleParameter(":BELONGEQUIP", OracleType.VarChar,255),
					new OracleParameter(":BELONGTRANSYS", OracleType.VarChar,100),
					new OracleParameter(":BELONGSTATION", OracleType.VarChar,65),
					new OracleParameter(":RECORDDATE", OracleType.DateTime),
					new OracleParameter(":ALARMDESC", OracleType.VarChar,255),
					new OracleParameter(":PRIMALCAUSE", OracleType.VarChar,100),
					new OracleParameter(":ALARMOBJECT", OracleType.VarChar,64),
					new OracleParameter(":TRANTYPE", OracleType.VarChar,3),
					new OracleParameter(":VENDOR", OracleType.VarChar,20),
					new OracleParameter(":BELONGDOMAIN", OracleType.VarChar,20),
					new OracleParameter(":EQUIPMODEL", OracleType.VarChar,12),
					new OracleParameter(":PACKTYPE", OracleType.VarChar,20),
					new OracleParameter(":PREEQUIP", OracleType.VarChar,33),
					new OracleParameter(":PRESTATION", OracleType.VarChar,20),
					new OracleParameter(":DEDUSEFAULT", OracleType.VarChar,1),
					new OracleParameter(":PERSISTTIME", OracleType.VarChar,64),
					new OracleParameter(":ISSYNC", OracleType.VarChar,2),
					new OracleParameter(":OBJECTCODE", OracleType.VarChar,255),
					new OracleParameter(":OBJCLASS", OracleType.VarChar,40),
					new OracleParameter(":ALARMTYPE", OracleType.VarChar,50),
					new OracleParameter(":PROBABLECAUSE", OracleType.VarChar,40),
					new OracleParameter(":ALARMTEXT", OracleType.VarChar,255),
					new OracleParameter(":ALARMLEVEL", OracleType.VarChar,32),
					new OracleParameter(":STARTTIME", OracleType.DateTime)};
            parameters[0].Value = model.ALARMNUMBER;
            parameters[1].Value = model.ENDTIME;
            parameters[2].Value = model.ISCLEARED;
            parameters[3].Value = model.CLEARPERSON;
            parameters[4].Value = model.ALARMEXPLAIN;
            parameters[5].Value = model.BELONGEQUIP;
            parameters[6].Value = model.BELONGTRANSYS;
            parameters[7].Value = model.BELONGSTATION;
            parameters[8].Value = model.RECORDDATE;
            parameters[9].Value = model.ALARMDESC;
            parameters[10].Value = model.PRIMALCAUSE;
            parameters[11].Value = model.ALARMOBJECT;
            parameters[12].Value = model.TRANTYPE;
            parameters[13].Value = model.VENDOR;
            parameters[14].Value = model.BELONGDOMAIN;
            parameters[15].Value = model.EQUIPMODEL;
            parameters[16].Value = model.PACKTYPE;
            parameters[17].Value = model.PREEQUIP;
            parameters[18].Value = model.PRESTATION;
            parameters[19].Value = model.DEDUSEFAULT;
            parameters[20].Value = model.PERSISTTIME;
            parameters[21].Value = model.ISSYNC;
            parameters[22].Value = model.OBJECTCODE;
            parameters[23].Value = model.OBJCLASS;
            parameters[24].Value = model.ALARMTYPE;
            parameters[25].Value = model.PROBABLECAUSE;
            parameters[26].Value = model.ALARMTEXT;
            parameters[27].Value = model.ALARMLEVEL;
            parameters[28].Value = model.STARTTIME;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public void Delete(string ALARMNUMBER)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete ALARM_HISTORY ");
            strSql.Append(" where ALARMNUMBER=:ALARMNUMBER ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,50)};
            parameters[0].Value = ALARMNUMBER;

            OracleHelper.ExecuteSql(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public FiberRMS.Model.AlarmManager.ALARM_HISTORY GetModel(string ALARMNUMBER)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,ALARMDESC,PRIMALCAUSE,ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,PERSISTTIME,ISSYNC,OBJECTCODE,OBJCLASS,ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME from ALARM_HISTORY ");
            strSql.Append(" where ALARMNUMBER=:ALARMNUMBER ");
            OracleParameter[] parameters = {
					new OracleParameter(":ALARMNUMBER", OracleType.VarChar,50)};
            parameters[0].Value = ALARMNUMBER;

            FiberRMS.Model.AlarmManager.ALARM_HISTORY model = new FiberRMS.Model.AlarmManager.ALARM_HISTORY();
            DataSet ds = OracleHelper.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.ALARMNUMBER = ds.Tables[0].Rows[0]["ALARMNUMBER"].ToString();
                if (ds.Tables[0].Rows[0]["ENDTIME"].ToString() != "")
                {
                    model.ENDTIME = DateTime.Parse(ds.Tables[0].Rows[0]["ENDTIME"].ToString());
                }
                model.ISCLEARED = ds.Tables[0].Rows[0]["ISCLEARED"].ToString();
                model.CLEARPERSON = ds.Tables[0].Rows[0]["CLEARPERSON"].ToString();
                model.ALARMEXPLAIN = ds.Tables[0].Rows[0]["ALARMEXPLAIN"].ToString();
                model.BELONGEQUIP = ds.Tables[0].Rows[0]["BELONGEQUIP"].ToString();
                model.BELONGTRANSYS = ds.Tables[0].Rows[0]["BELONGTRANSYS"].ToString();
                model.BELONGSTATION = ds.Tables[0].Rows[0]["BELONGSTATION"].ToString();
                if (ds.Tables[0].Rows[0]["RECORDDATE"].ToString() != "")
                {
                    model.RECORDDATE = DateTime.Parse(ds.Tables[0].Rows[0]["RECORDDATE"].ToString());
                }
                model.ALARMDESC = ds.Tables[0].Rows[0]["ALARMDESC"].ToString();
                model.PRIMALCAUSE = ds.Tables[0].Rows[0]["PRIMALCAUSE"].ToString();
                model.ALARMOBJECT = ds.Tables[0].Rows[0]["ALARMOBJECT"].ToString();
                model.TRANTYPE = ds.Tables[0].Rows[0]["TRANTYPE"].ToString();
                model.VENDOR = ds.Tables[0].Rows[0]["VENDOR"].ToString();
                model.BELONGDOMAIN = ds.Tables[0].Rows[0]["BELONGDOMAIN"].ToString();
                model.EQUIPMODEL = ds.Tables[0].Rows[0]["EQUIPMODEL"].ToString();
                model.PACKTYPE = ds.Tables[0].Rows[0]["PACKTYPE"].ToString();
                model.PREEQUIP = ds.Tables[0].Rows[0]["PREEQUIP"].ToString();
                model.PRESTATION = ds.Tables[0].Rows[0]["PRESTATION"].ToString();
                model.DEDUSEFAULT = ds.Tables[0].Rows[0]["DEDUSEFAULT"].ToString();
                model.PERSISTTIME = ds.Tables[0].Rows[0]["PERSISTTIME"].ToString();
                model.ISSYNC = ds.Tables[0].Rows[0]["ISSYNC"].ToString();
                model.OBJECTCODE = ds.Tables[0].Rows[0]["OBJECTCODE"].ToString();
                model.OBJCLASS = ds.Tables[0].Rows[0]["OBJCLASS"].ToString();
                model.ALARMTYPE = ds.Tables[0].Rows[0]["ALARMTYPE"].ToString();
                model.PROBABLECAUSE = ds.Tables[0].Rows[0]["PROBABLECAUSE"].ToString();
                model.ALARMTEXT = ds.Tables[0].Rows[0]["ALARMTEXT"].ToString();
                model.ALARMLEVEL = ds.Tables[0].Rows[0]["ALARMLEVEL"].ToString();
                if (ds.Tables[0].Rows[0]["STARTTIME"].ToString() != "")
                {
                    model.STARTTIME = DateTime.Parse(ds.Tables[0].Rows[0]["STARTTIME"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ALARMNUMBER,ENDTIME,ISCLEARED,CLEARPERSON,ALARMEXPLAIN,BELONGEQUIP,BELONGTRANSYS,BELONGSTATION,RECORDDATE,ALARMDESC,PRIMALCAUSE,ALARMOBJECT,TRANTYPE,VENDOR,BELONGDOMAIN,EQUIPMODEL,PACKTYPE,PREEQUIP,PRESTATION,DEDUSEFAULT,PERSISTTIME,ISSYNC,OBJECTCODE,OBJCLASS,ALARMTYPE,PROBABLECAUSE,ALARMTEXT,ALARMLEVEL,STARTTIME ");
            strSql.Append(" FROM ALARM_HISTORY ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return OracleHelper.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            OracleParameter[] parameters = {
                    new OracleParameter(":tblName", OracleType.VarChar, 255),
                    new OracleParameter(":fldName", OracleType.VarChar, 255),
                    new OracleParameter(":PageSize", OracleType.Number),
                    new OracleParameter(":PageIndex", OracleType.Number),
                    new OracleParameter(":IsReCount", OracleType.Clob),
                    new OracleParameter(":OrderType", OracleType.Clob),
                    new OracleParameter(":strWhere", OracleType.VarChar,1000),
                    };
            parameters[0].Value = "ALARM_HISTORY";
            parameters[1].Value = "ID";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  成员方法
    }
}

